import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver

class HomePage:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/home"       # 首页对应的url
        self.driver = QESDriver.driver                  # 创建驱动
        self.driver.get(self.url)                       # 访问首页

    # 点击、查找首页对应的元素
    def GetHomePage(self):
        # 查找首页元素并截图
        home = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[1]/div/span').text
        # assert home == "首页"
        navigation_bar = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[1]/div/div').text
        assert navigation_bar == "快速开始 / 便捷导航"
        QESDriver.GetScreenShot()
        ##########################################################################################
        # 查找“我的考试”并点击
        self.driver.find_element(By.XPATH,'//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[1]').click()
        # 查找“我的问卷”并点击
        self.driver.find_element(By.XPATH,'//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[2]').click()
        # 查找“问卷记录”并点击
        self.driver.find_element(By.XPATH,'//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[3]').click()
        # 查找“考试记录”并点击
        self.driver.find_element(By.XPATH,'//*[@id="rc-tabs-0-panel-exam"]/div/div/div/div[2]/div/div/div/div/div/table/thead/tr/th[4]').click()

    def HP_CreateQuestionnaire(self):
        # 点击创建问卷并截图
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/a[1]').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()

        self.driver.back()

    def HP_CreateExaminations(self):
        # 点击创建考试并截图
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[2]/div/div[2]/div/a[2]').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()

        self.driver.back()

